angular
    .module("app", ["ui.router"])
    .config(function ($stateProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $stateProvider.state("home", {
            url: "/",
            templateUrl: "partials/home.html"
        }).state("home.alpha", {
            url: "alpha",
            templateUrl: "partials/home.detail.html"
        }).state("home.bravo", {
            url: "bravo",
            templateUrl: "partials/home.detail.html"
        }).state("home.charlie", {
            url: "charlie",
            templateUrl: "partials/home.detail.html"
        });
    })
    .directive("mdlUpgrade", function ($timeout) {
        return {
            restrict: "A",
            compile: function (tElement, tAttrs, transclude) {
                return {
                    post: function (scope, iElement, iAttrs, controller) {
                        $timeout(function () {
                            componentHandler.upgradeElement(iElement[0]);
                        }, 200);
                    }
                };
            }
        };
    })
    .directive("mdlJsCheckbox", function () {
        return {
            restrict: "C",
            link: function (scope, element, attrs, controller, transcludeFn) {
                scope.$watch(function () {
                    return scope.item.completed;
                }, function (newValue, oldValue) {
                    if (newValue) {
                        if (element[0].MaterialCheckbox) {
                            element[0].MaterialCheckbox.check();
                        }
                    } else {
                        if (element[0].MaterialCheckbox) {
                            element[0].MaterialCheckbox.uncheck();
                        }
                    }
                });
            }
        };
    })
    .directive("mdlJsSwitch", function () {
        return {
            restrict: "C",
            link: function (scope, element, attrs, controller, transcludeFn) {
                scope.$watch(function () {
                    return scope.item.completed;
                }, function (newValue, oldValue) {
                    if (newValue) {
                        if (element[0].MaterialSwitch) {
                            element[0].MaterialSwitch.on();
                        }
                    } else {
                        if (element[0].MaterialSwitch) {
                            element[0].MaterialSwitch.off();
                        }
                    }
                });
            }
        };
    });